export default {
	data (){
		return{
			 
			modal1:false,
			ids:[
				
			],
			list:[],
			filter:{
				page: 1,
				limit: 2,//一页显示2条
				name:'',
				total:0,
			}
		}
	},
	methods:{
		clickselect(selection,row){
			this.ids.push(row._id)
			
		},
		removeSelectAll(){
			this.ids.forEach((id)=>{

				this.$http({
    				method:'delete',
    				url:`http://localhost:3000/${this.module1}/data/`+id,

    			}).then((response)=>{
        		
					this.getData();
        		})
			})
			
		},
	 	handleSelectAll (status) {
            this.$refs.selection.selectAll(status);
            
       	},
		changeSize(pageSize){
			console.log(pageSize)
			this.filter.limit = pageSize;
			this.getData();
		},
		changePage(page){
			this.filter.page = page;
			this.getData();
		},
//		skip(id){		
//  		this.$http({
//      		url:'http://localhost:3000/comment/list',
//      		method:'post',
//      		data:{
//      			newId:id       			
//      		}
//      	}).then(res=>{
//				console.log(res.data)
//				this.list = res.data.rows;
//				this.filter.total= res.data.total;
//				console.log(this.filter)
//      	}) 
//   
//  	},
		getData(){
			console.log(this.filter)
			this.$http({
				method:'post',
				url:`http://localhost:3000/${this.module1}/list`,
				data:this.filter
			})
			.then(res=>{
				this.list = res.data.rows;
				this.filter.total = res.data.total;

			})
		},
		search(){
			this.getData()
		},
		editData(id){
			this.$http({
					method:'GET',
					url:`http://localhost:3000/${this.module1}/data/`+id,
				
				}).then((response)=>{
	    		
	    		this.formValidate=response.data
	    	})
				this.modal1 = true;
	//      			$('#inp').val(id)
				
		},
    	removeData(id){
    		this.$http({
    				method:'delete',
    				url:`http://localhost:3000/${this.module1}/data/`+id,
    				async:true
    			}).then((response)=>{
        		
					this.getData();
        	})
    	},
    	show(id){
    		this.$http({
    				method:'GET',
    				url:`http://localhost:3000/${this.module1}/data/`+id,
    			
    			}).then((response)=>{
        		
        		this.$Modal.info({
                    title: '用户信息',
                    content: `姓名：${response.data.name}<br>年龄：${response.data.password}<br>地址：${response.data.mail}`
                	})
        		})

    	},
    	handleSubmit (name) {
        		
        		if(this.formValidate._id){
        			this.$refs[name].validate((valid) => {
	                    if (valid) {
	                    	this.$http({
			        				method:'POST',
			        				url:`http://localhost:3000/${this.module1}/data/`+this.formValidate._id,
			        				data:this.formValidate
			        			}).then(res=>{
									this.getData();
			            	})
	                    	
	                    	
	                        this.$Message.success('修改成功!');
	                    } else {
	                        this.$Message.error('表单验证失败!');
	                    }
	                })
        		}else{
        			console.log(this.formValidate)
        			this.$refs[name].validate((valid) => {
	                    if (valid) {
	                    	
	                    	this.$http({
			        				method:'POST',
			        				url:`http://localhost:3000/${this.module1}/data/`,
			        				data:this.formValidate
			        			}).then(res=>{
//			        				this.$refs[name].resetFields();
			            	})
	                    	
	                    	
	                        this.$Message.success('提交成功!');
	                    } else {
	                        this.$Message.error('表单验证失败!');
	                    }
	                })
        		}
                
            },
            handleReset (name) {
                this.$refs[name].resetFields();
            },
        	ok () {
              	this.$Message.info('点击了确定');
            },
            cancel () {
                this.$Message.info('点击了取消');
            },
        	addData(){
        		this.modal1 = true
        	}
        	
	},
	created(){
		this.getData();
	}
}
